﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Handrise.CDCable.Mobile.Business;

namespace Handrise.CDCable.Mobile.UI
{
    public partial class FrmRecordLst : FrmBase
    {
        private string parentForm = "";
        private string linkIDs = "";
        private LinkFileService linkFileService = new LinkFileService();

        private Plan plan = null;

        public FrmRecordLst()
        {
            InitializeComponent();
            ttlbrhead.Text = "录音管理";
            ilstbcup.Images.Add(ResourceImage.空白);
            ilstbcup.Images.Add(ResourceImage.空白);
            ilstbcup.Images.Add(ResourceImage.返回01);
            ilstbcdown.Images.Add(ResourceImage.空白);
            ilstbcdown.Images.Add(ResourceImage.空白);
            ilstbcdown.Images.Add(ResourceImage.返回02);

        }

        private void Frmrecordlst_Load(object sender, EventArgs e)
        {
            if (IsReturn)
                LoadCacheData();
            else
                LoadData();

            //加载关联的图片
            List<LinkFile> linkFiles = linkFileService.GetLinkFileByLinkIDAndType(linkIDs, "wav");

            dlRecord.DisplayMember = "Title";
            dlRecord.DataSource = linkFiles;
            dlRecord.DataBind();

            SetButtonState();
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadData()
        {
            parentForm = (string)Parameter[0];
            linkIDs = (string)Parameter[1];

            if (Parameter.Count > 2)
                plan = (Plan)Parameter[2];
        }

        /// <summary>
        /// 加载缓存数据
        /// </summary>
        private void LoadCacheData()
        {
            parentForm = (string)Caches[0];
            linkIDs = (string)Caches[1];

            if (Caches.Count > 2)
                plan = (Plan)Caches[2];
        }

        private void dlsttask_OnItemClick(HandRise.MBHOP.Controls.DataListItem item)
        {

            LinkFile linkFile = (LinkFile)item.DataSource;

            FormManage.GotoNext("FrmRcrdPlyBck", new object[] { linkFile,plan }, new object[]{parentForm ,linkIDs,plan}, false);
        }

        private void bcOperate_OnButtonClick(object sender, int buttonIndex)
        {
            switch (buttonIndex)
            {
                case 2: //返回
                    FormManage.GotoNext(parentForm, null, null, true);
                    break;

            }
        }

        private void btnPrior_Click(object sender, EventArgs e)
        {
            dlRecord.PreviousPage();
            SetButtonState();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            dlRecord.NextPage();
            SetButtonState();
        }

        private void SetButtonState()
        {
            btnNext.Enabled = dlRecord.PageCount > 0 && dlRecord.PageIndex < dlRecord.PageCount;
            btnPrior.Enabled = dlRecord.PageCount > 0 && dlRecord.PageIndex > 1;
        }
    }
}